package 力扣日常刷题.木22一月.第02天0109;

/**
 * @author 帅小伙
 * @date 2022/1/9
 * @description https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/
 * 每行每列最大的最小值
 */
public class Demo05数组中等城市天际线 {

    public int maxIncreaseKeepingSkyline(int[][] grid) {
        int n = grid.length;
        int row[] = new int[n];
        int line[] = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (row[i] < grid[i][j]) {
                    row[i] = grid[i][j];
                }
                if (line[i] < grid[j][i]) {
                    line[i] = grid[j][i];
                }
            }
        }

        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int min = Math.min(row[i], line[j]);
                res +=(min-grid[i][j]);
            }
        }
        return res;
    }
}
